#!/usr/bin/env bash
commit_message=$1
if [ ! -n "${commit_message}" ] ;then
    commit_message=`date +%Y-%m-%d,%H:%m:%S`
fi

git fetch origin master
git merge
git add ./
diff=`git diff origin/master`
if [ -n "$diff" ] ;then
    echo "auto push diff code:"
    echo "$diff"
    git add ./
    git commit -m "shell auto commit  code ${commit_message}"
    git push origin master
    if [ ! $? -eq 0 ] ;then
           echo "push failed,retry"
           git push origin master
    fi
    if [ ! $? -eq 0 ] ;then
        echo "failed to sync code to git repository"
        exit -1
    fi
else
    echo "no file need to update"
    exit 0
fi

echo "file upload success" 